import Vue from 'vue'
import App from './App.vue'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import './assets/gloable.css'
import request from './utils/request';

import mavonEditor from 'mavon-editor';
import 'mavon-editor/dist/css/index.css'
Vue.use(mavonEditor)


Vue.config.productionTip = false
Vue.use(ElementUI,{size:"mini"});

// Vue.prototype.request=request
// 将axios实例绑定到Vue原型上，方便在组件中使用
Vue.prototype.$http = request

// 为路由对象，添加beforeEach导航守卫
router.beforeEach((to,from, next)=> {
  //如果用户访问的登录页，直接放行
  if(to.path === '/login'|| to.path==='/register' || to.path==='/front/home'){
    return next()
  }else{
    //从localStorage中获取到保存的token值
    // const tokenStr = localStorage.getItem("token")
    if(!localStorage.getItem("token")) {
      return next('/login') //没有token，强制跳转到登录页
    }else{
      next()
    }       
  }
  
})


new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
